<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2022/4/2
  Time: 20:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@include file="com/com.jsp"%>
    <style>
        h1{
            color: #3e8f3e;
        }
        a{
            text-decoration: none;
            color: beige;

        }
    </style>
    <script>
        function del() {
            return confirm("你确定要删除吗？");
        }
    </script>
</head>
<body>
    <%--搭建页面信息--%>
    <div class="container">
        <%--标题--%>
        <div class="row">
            <div class="col-md-12">
                <h1>实现增删查改</h1>
            </div>
        </div>
            <%--按钮--%>
        <div class="row">
            <div class="col-md-4 col-md-offset-8">
                <button class="btn btn-primary"><a href="${pageContext.request.contextPath}/pages/emp_add.jsp">添加</a></button>
                <button class="btn btn-danger">删除</button>
            </div>
        </div>
            <%--显示数据--%>
        <div class="row">
            <div class="col-md-12">
                <table class="table table-hover table-bordered">
                    <tr>
                        <th>编号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>邮箱</th>
                        <th>所属部门</th>
                        <th>操作</th>
                    </tr>
                    <c:forEach items="${pages.list}" var="pag">
                        <tr>
                            <th><input type="checkbox">${pag.emp_id}</th>
                            <th>${pag.name}</th>
                            <th>${pag.gender}</th>
                            <th>${pag.email}</th>
                            <th>${pag.dep_name}</th>
                            <th>
                                <button class="btn btn-primary btn-sm">
                                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                   <a href="/employee/delete">编辑</a>
                                </button>
                                <button class="btn btn-danger btn-sm">
                                    <span class="glyphicon glyphicon-trash " aria-hidden="true"></span>
                                    <a href="${pageContext.request.contextPath}/employee/delete?emp_id=${pag.emp_id}" onclick="del()">删除</a>
                                </button>
                            </th>
                        </tr>
                    </c:forEach>

                </table>
            </div>
        </div>
            <%--分页--%>
        <div class="row">
            <%--分页信息--%>
            <div class="col-md-6">
                <nav aria-label="Page navigation">
                    <ul class="pagination">

                        <li><a href="${pageContext.request.contextPath}/employee/findAll?pn=1">首页</a></li>
                        <%--如果有上一页就显示上一页符号--%>
                        <li>
                            <c:if test="${pages.hasPreviousPage}">
                                <a href="${pageContext.request.contextPath}/employee/findAll?pn=${pages.pageNum-1}">上一页</a>
                            </c:if>
                        </li>
                        <c:if test="${pages.hasPreviousPage}">
                            <li>
                                <a href="${pageContext.request.contextPath}/employee/findAll?pn=${pages.pageNum-1}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                        </c:if>

                        <c:forEach items="${pages.navigatepageNums}" var="page">
                            <%--pageNum是当前页  如果是当前页 数字高亮--%>
                            <c:if test="${page==pages.pageNum}">
                                <li><a href="#" class="active">${page}</a></li>
                            </c:if>
                            <c:if test="${page!=pages.pageNum}">
                                <li>
                                    <a href="${pageContext.request.contextPath}/employee/findAll?pn=${page}>${page}</a>
                                </li>
                            </c:if>
                        </c:forEach>
                        <%--如果有上一页就显示上一页符号--%>
                        <c:if test="${pages.hasNextPage}">
						   <li>
                                    <a href="${pageContext.request.contextPath}/employee/findAll?pn=${pages.pageNum+1}" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                        </c:if>
                        <li>
                            <c:if test="${pages.hasNextPage}">
                                <a href="${pageContext.request.contextPath}/employee/findAll?pn=${pages.pageNum+1}">下一页</a>
                            </c:if>
                        </li>
                        <li><a href="${pageContext.request.contextPath}/employee/findAll?pn=${pages.pages}">末页</a></li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</body>
</html>
